package com.cooba.content_frament;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.fastjson.JSON;
import com.cooba.R;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

/**
 * Created by Administrator on 2015/12/7.
 * 游戏
 */
public class GameFrament extends Fragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    private View contentview;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (contentview == null) {
            contentview = initview(inflater);
        }
        return contentview;
    }

    //初始化控件
    private View initview(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.game_frament, null, false);
        getMac();
        return view;
    }

    private void getMac() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams params = new RequestParams();
        httpUtils.send(HttpRequest.HttpMethod.GET, "http://a.cooba.cc/macmark.json", params, new RequestCallBack<String>() {
            @Override
            public void onFailure(HttpException arg0, String arg1) {
               Log.e("ssssss", "获取mac失败");
            }

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String mac = JSON.parseObject(responseInfo.result).getString("MAC");
                Log.e("ssssss", "获取成功mac>>>"+mac);
            }

        });
    }
}
